# Maintainer: Bradley Saulteaux <-@bradso.to>
pkgname=bluez-alsa
pkgver=4.0.0
pkgrel=2
pkgdesc="Bluetooth Audio ALSA Backend"
url="https://github.com/Arkq/bluez-alsa"
arch="all"
license="MIT"
depends="bluez"
subpackages="$pkgname-openrc $pkgname-utils"
makedepends="automake autoconf libtool alsa-lib-dev bluez-dev glib-dev sbc-dev
	dbus-dev fdk-aac-dev libbsd-dev ncurses-dev readline-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/Arkq/bluez-alsa/archive/v$pkgver.tar.gz
	bluealsa.initd
	bluealsa.confd
	0001-remove-bsd-sys-time.h-include.patch
	"

prepare() {
	default_prepare
	autoreconf --install
	mkdir build
}

build() {
	cd build
	../configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-aac \
		--enable-ofono \
		--enable-cli \
		--enable-rfcomm \
		--enable-a2dpconf \
		--enable-hcitop \
		--disable-static \
		--with-dbusconfdir=/usr/share/dbus-1/system.d
	make
}

check() {
	cd build
	make check
}

package() {
	cd build
	make DESTDIR="$pkgdir" install
	install -Dm755 ../../bluealsa.initd "$pkgdir"/etc/init.d/bluealsa
	install -Dm644 ../../bluealsa.confd "$pkgdir"/etc/conf.d/bluealsa
}

utils() {
	pkgdesc="Bluetooth Audio ALSA Backend utils"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/bluealsa-aplay "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/bluealsa-cli "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/bluealsa-rfcomm "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/a2dpconf "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/hcitop "$subpkgdir"/usr/bin/
}

sha512sums="
8a79e5a1189db2d39b2d772cb8f8cd51ebb96b9bd91489556195e83dfd16f40a581dce68c5ad9e886b66cec8a03ae7f959e8288bb4c5c87ea5a2bbd6aee9c5f0  bluez-alsa-4.0.0.tar.gz
3a631e940cc56f3f7b9a49f5e69d057be08e876334d29ec9e0839ad80e8829d970e099d01f180a1e4fef237f324bcb16abdc702dbb6d0b46e3d318625e805cae  bluealsa.initd
ae50f9c39b8f725f793f362336d1823b1c20ebf877b1ae736601ef48e030b8c79094018d270e098476dc98ef888aae577e7a0ebda70451c3168d79c5e2baf859  bluealsa.confd
f84519d08f55bdde495f1cb881628288301478ef5ed10e58df0787a12535e08c55ccac7a62d6f8857d650335a0161f5fa92ba14ce8405c0d02e3b2a8b08e36ac  0001-remove-bsd-sys-time.h-include.patch
"
